﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DataStructDemo.LikedListDemo
{
    public class InsertHeadWay<T>
    {
        private class Node
        {
            private T _data;
            public T Data
            {
                get { return _data; }
                set { _data = value; }
            }

            private Node _nextNode;
            public Node NextNode
            {
                get { return _nextNode; }
                set { _nextNode = value; }
            }

            public Node(T t)
            {
                _nextNode = null;
                Data = t;
            }
        }

        private Node _head;

        public InsertHeadWay() 
        {
            _head = null;
        }

        public void AddHead(T t)
        {
            var node=new Node(t) {NextNode = _head};
            _head = node;
        }

        public IEnumerable<T>  GetEnumerable()
        {
            Node current = _head;
            while (current!=null)
            {
                yield return current.Data;
                current = current.NextNode;
            }
        }

    }
}
